﻿namespace Nomo.UnityCoreModule.AI
{
    /// <summary>
    /// 圆形区域漂浮物。
    /// </summary>
    public sealed class CircleFloater2D : Floater
    {
        /// <summary>
        /// 可漂浮区域的半径。
        /// </summary>
        [UnityEngine.Min(0F)] public float radius;

        /// <inheritdoc />
        protected override bool ShouldUpdateTarget => UnityEngine.Vector3.SqrMagnitude(Current - Target) < 1E-9;

        /// <inheritdoc />
        protected override bool StateValid => radius > 0F;

        /// <inheritdoc />
        public override void UpdateTarget()
        {
            Target = Origin + (UnityEngine.Vector3) UnityEngine.Random.insideUnitCircle * radius;
        }

        /// <inheritdoc />
        protected override void OnFloat()
        {
            Current = UnityEngine.Vector3.MoveTowards(Current, Target, speed * UnityEngine.Time.deltaTime);
        }
    }
}
